namespace SolidMvvm {
	using System;
	using System.Globalization;
	using System.Windows.Data;

	/// <summary>
	///     Convert decimal to hex and back.
	/// </summary>
	[ValueConversion(typeof(string), typeof(int))]
	public class IntToHexStringConverter : IValueConverter {
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			if (value == null || !(value is int))
				throw new ArgumentException("Converter value is either null or not an integer.");

			return ((int)value).ToString("X");
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			if (value == null || !(value is string))
				throw new ArgumentException("Converter value is either null or not an integer.");

			return Conversions.HexOrBinaryOrDecimalStringToInt("x" + value);
		}
	}
}
